<template>
  <page-header-wrapper :title="false">
    <a-card title="拒开发票列表">
      <div class="table-page-search-wrapper">
        <a-form-model :model="queryParam" layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-model-item label="提交顾问">
                <a-select
                  show-search
                  v-model="queryParam['filter[adviser_uid]']"
                  placeholder="选择顾问姓名"
                  :filter-option="filterOption"
                >
                  <a-select-option v-for="(item,index) in adviserOpts" :key="index" :value="index">{{item}}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="申请时间">
                <a-range-picker @change="onCreateAt" />
              </a-form-item>
            </a-col>
            <template v-if="advanced">
              <a-col :md="6" :sm="24">
                <a-form-item label="拒绝时间">
                  <a-range-picker @change="onCheckAt" />
                </a-form-item>
              </a-col>
            </template>
            <a-col :md="!advanced && 8 || 24" :sm="24">
                <span class='table-page-search-submitButtons' :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
                  <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                  <a-button style="margin-left: 8px" @click="resetSearch">重置</a-button>
                  <a @click="toggleAdvanced" style="margin-left: 8px">
                    {{ advanced ? '收起' : '展开' }}
                    <a-icon :type="advanced ? 'up' : 'down'" />
                  </a>
                </span>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <s-table
        bordered
        ref="table"
        :row-key="(record) => record.id"
        :columns="invoiceColumns"
        :data="invoiceData"
      >
        <template slot="contract_no" slot-scope="text,record">
          <a-button v-if="text == '合并合同'" type="link" @click="toDetail(record.id)">{{text}}</a-button>
          <a-button v-else type="link" @click="$router.push({ name: 'ContractDetail', params: { id: record.contract_id } })">{{text}}</a-button>
        </template>
        <template slot="company_name" slot-scope="text,record">
          {{text}}({{record.tax_point}}%)
        </template>
        <template slot="tm_name" slot-scope="text,record">
          {{text}}{{record.pt_name}}
        </template>
        <template slot="username" slot-scope="text, record">
          <a-tag>{{text}}</a-tag><br>
          <a-tag>{{record.group_type}}组</a-tag><br>
          <a-tag>{{record.leader_name}}</a-tag>
        </template>
        <template slot="action" slot-scope="text,record">
          <a-button size="small" type="primary" @click="toDetail(record.id)">详情</a-button>
        </template>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
  import storage from 'store'
  import { ACCESS_TOKEN } from '@/store/mutation-types'
  import { STable } from '@/components'
  import invoiceColumns from '@/columns/invoice'
  import { getUnInvoice } from '@/api/invoice'

  export default {
    components: {
      STable
    },
    name: 'RefuseInvoiceList',
    data () {
      return {
        invoiceColumns: invoiceColumns.refuseInvoice,
        invoiceData: parameters => {
          return getUnInvoice(Object.assign(parameters, this.queryParam)).then(res => {
            this.adviserOpts = res.result.all_advisers
            return res.result
          })
        },
        searchText: '',
        searchInput: null,
        searchedColumn: '',
        queryParam: {},
        advanced: true,
        header: {
          'Access-Token': storage.get(ACCESS_TOKEN)
        },
        adviserOpts: {}
      }
    },
    created () {
      this.queryParam['filter[status]'] = '50'
    },
    methods: {
      toDetail (id) {
        this.$router.push({ name: 'InvoiceDetail', params: { id } })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      resetSearch () {
        // this.queryParam = {}
        this.queryParam['filter[adviser_uid]'] = ''
        this.queryParam['filter[created_at_start]'] = ''
        this.queryParam['filter[created_at_end]'] = ''
        this.queryParam['filter[check_time_start]'] = ''
        this.queryParam['filter[check_time_end]'] = ''
        this.$refs.table.refresh(true)
      },
      onCreateAt (date, dateString) {
        this.queryParam['filter[created_at_start]'] = dateString[0]
        this.queryParam['filter[created_at_end]'] = dateString[1]
      },
      onCheckAt (date, dateString) {
        this.queryParam['filter[check_time_start]'] = dateString[0]
        this.queryParam['filter[check_time_end]'] = dateString[1]
      },
      filterOption (input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        )
      }
    }
  }
</script>

<style scoped>

</style>
